<template>
  <PublicPage bgColor="#F5F5F5">
    <view class="p-3 bg-white">
      <UserCard
        :avatar="info.headimg"
        avatarClass="w-16 h-16 rounded-full"
        :userName="info.userName"
        :deptName="info.deptname"
        :postName="info.postName"
        :com="info.com"
        :mobile="info.mobile">
        <template #status>
          <!-- 0未认证 1成功 2已申请 3失败 -->
          <u-tag v-if="info.apStatus === ExpertApStatusEnum.SUCCEED" text="已认证" type="primary" size="mini" plain plainFill icon="checkmark-circle-fill" />
          <u-tag v-else-if="info.apStatus === ExpertApStatusEnum.ERROR" text="认证失败" type="error" size="mini" plain plainFill />
          <u-tag v-else text="认证中" type="success" size="mini" plain plainFill />
        </template>
      </UserCard>

      <view  style="border-top: solid 1px #f5f5f5;" class="flex items-center justify-center pt-3" @click="goEditExpert">
        <image src="@/static/image/icon/icon_edit.png" class="w-4 h-4" />
        <view class="pl-3">修改医生信息</view>
      </view>
    </view>

    <view class="p-3">
      <view class="pt-2">
        <text class="text-base font-bold">医生数据</text>
        <text class="pl-2 u-content-color">更新时间: {{ newTimes }}</text>
      </view>
      <view class="grid grid-cols-3 py-4 my-4 text-white rounded-lg gap-x-3 u-primary-bg">
        <view class="text-center">
          <view class="pb-3 text-xl font-medium">{{ info.billNum || 0 }}</view>
          <view>开单数量(单)</view>
        </view>
        <view class="text-center">
          <view class="pb-3 text-xl font-medium">￥{{ info.billAmount || 0 }}</view>
          <view>开单金额(元)</view>
        </view>
        <view class="text-center">
          <view class="pb-3 text-xl font-medium">{{ info.patientNum || 0 }}</view>
          <view>患者数(人)</view>
        </view>
      </view>

      <view class="pt-2">
        <text class="text-base font-bold">设备数据</text>
        <text class="pl-2 u-content-color">{{ info.serialNo }}</text>
      </view>
      <view class="grid grid-cols-3 py-4 my-4 bg-white rounded-lg gap-x-3">
        <view class="text-center">
          <view class="pb-3 text-xl font-medium">{{ info.deviceAllocationTime || '- ' }}</view>
          <view>设备分配时间</view>
        </view>
        <view class="text-center">
          <view class="pb-3 text-xl font-medium">{{ info.sevenUsageDays || 0 }}</view>
          <view>7日内使用天数</view>
        </view>
        <view class="text-center">
          <view class="pb-3 text-xl font-medium">{{ info.thirtyUsageDays || 0 }}</view>
          <view>近30天内开机天数</view>
        </view>
        <view class="text-center">
          <view class="pb-3 text-xl font-medium">{{ info.weekUsageDays || 0 }}</view>
          <view>本周APP使用天数</view>
        </view>
        <view class="text-center">
          <view class="pb-3 text-xl font-medium">{{ info.monthUsageDays || 0 }}</view>
          <view>本月APP使用天数</view>
        </view>
      </view>
    </view>
  </PublicPage>
</template>

<script setup lang="ts">
import UserCard from '@/components/userCard.vue'
import dayjs from 'dayjs'
import { expertDetails } from '@/api/expert'
import { PageTypeEnum } from '@/utils/enums';
import { ExpertApStatusEnum } from '@/utils/enums';
import { refreshOnLoad } from "@/hooks/refreshPage";

const info = ref<any>({});
const newTimes = ref<string>(); 
const getData = async (id: number) => {
  newTimes.value = dayjs().format('YYYY-MM-DD HH:mm');
  const { data } = await expertDetails(id);
  info.value = data;
}

// 跳转修改医生
const goEditExpert = () => {
  if(unref(info).apStatus === ExpertApStatusEnum.APPLIED){
    uni.showToast({
      title: '审核中,请耐心等待!',
      icon: 'none'
    })
    return
  }
  uni.$u.route({
    type: 'navigateTo',
    url: '/pages/expert/editExport',
    params: {
      id: unref(info).id,
      pageType: PageTypeEnum.EDIT
    }
  })
};

onLoad((options) => {
  getData(options?.id);
});
onShow(()=> {
  refreshOnLoad((options: any) => { getData(options?.id) });
});
</script>

<style lang="scss" scoped></style>
